package com.ruoyi.project.km.projectManager.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.km.projectManager.domain.KmPro;
import com.ruoyi.project.km.projectManager.mapper.ProManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProManagerServiceImpl  implements ProManagerService{
    //声明Mapper层属性
    @Autowired
    private ProManagerMapper proManagerMapper;
    //加载项目信息列表
    @Override
    public List<KmPro> selectKmProList(KmPro kmPro)
    {
        return proManagerMapper.selectKmProMapper(kmPro);
    }

    //校验项目名称是否被占用
    @Override
    public String checkKmProNameUniqueService(KmPro kmPro) {
        Integer proId = StringUtils.isNull(kmPro.getProId()) ? -1 : kmPro.getProId();
        KmPro info = proManagerMapper.checkKmProNameUniqueMapper(kmPro.getProName());
        if (StringUtils.isNotNull(info) && info.getProId().intValue() != proId.intValue())
        {
            return UserConstants.POST_NAME_NOT_UNIQUE;
        }
        return UserConstants.POST_NAME_UNIQUE;
    }

    //新增项目信息
    @Override
    public int insertKmPro(KmPro kmPro) {
        return proManagerMapper.insertKmProMapper(kmPro);
    }

    //根据项目编号获取项目信息
    @Override
    public KmPro selectKmProById(Integer proId) {
        return proManagerMapper.selectKmProByIdMapper(proId);
    }

    //修改项目信息
    @Override
    public int updateKmPro(KmPro kmPro) {
        if (kmPro.getProState().intValue()==4){
            kmPro.setProState(5);
        }
        return proManagerMapper.updateKmProMapper(kmPro);
    }

    //删除指定编号的项目信息(支持多选删除)
    @Override
    public int deleteKmProByIds(String ids) {
        Integer[] proIds = Convert.toIntArray(ids);

        return proManagerMapper.deleteKmProByIds(proIds);
    }

    @Override
    public int updatePrettyById(KmPro kmPro) {
        return proManagerMapper.updatePrettyByIdMapper(kmPro);
    }
}
